﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.SysOperation>" %>

<!DOCTYPE html>
<html>
<head id="Head1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>操作</title>
    <script src="<%: Url.Content("~/Scripts/jquery.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/JScriptIndex.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Res/easyui/jquery.easyui.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Res/easyui/locale/easyui-lang-zh_CN.js") %>" type="text/javascript"></script>
    <link href="<%: Url.Content("~/Res/easyui/themes/default/easyui.css") %>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Res/easyui/themes/icon.css") %>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Content/StyleSheet.css") %>" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        $(function () {
            $('#myTree').tree({
                url: '../PersonTree/GetTree',
                onClick: function (node) {
                    if (node != null && node.id != null && node.id != "undefined") {
                        $('#hidtreeid').val(node.id);
                        $('#flexigridData').datagrid({
                            title: '业务', //列表的标题
                            width: 'auto',
                            height: 'auto',
                            queryParams: {
                                userguid: node.id
                            },
                            toolbar: [
                                {
                                    text: '确定',
                                    iconCls: 'icon-edit',
                                    handler: function () {
                                        return setSure();
                                    }
                                }
                            ],
                            url: '../PersonAndBusiness/GetAllYeWu', //获取数据的url
                            columns: [[
                                { field: 'ck', checkbox: true },
                                { field: 'Name', title: '<%: Html.DisplayNameFor(model => model.Name) %>', width: 226 },
                                { field: 'depatrmentname', title: '业务所属单位', width: 226 }
                            ]],
                            onLoadSuccess: function (data) {
                                if (data) {
                                    $.each(data.rows, function (index, item) {
                                        if (this.ischecked>0) {
                                            $('#flexigridData').datagrid('checkRow', index);
                                        }
                                    });
                                }
                            }
                        });
                    }
                },
                onBeforeLoad: function (node, param) {
                    if (node) {
                        param.parentid = node.id;
                    }
                }
            });
        });
             //设置
             function setSure() {
                 var arr = $('#flexigridData').datagrid('getChecked');
                 var userguid = $('#hidtreeid').val();
                 $.ajax({
                     async: false,
                     cache: false,
                     url: "../PersonAndBusiness/DeleteYW",
                     dataType: "text",
                     data: { "PersonGuid": userguid },
                     success: function (msg) {
                     }
                 });
                 var count = 0;
                 var successcount = 0;
                 $.each(arr, function (index, item) {
                     count++;
                     $.ajax({
                         async: false,
                         cache: false,
                         url: "../PersonAndBusiness/UpdateYw",
                         dataType: "text",
                         data: { "PersonGuid": userguid, "BusinessGuid": item.RowGuid },
                         success: function (msg) {
                             if(msg="success")
                             {
                                 successcount++;
                             }
                         }
                     });
                 });
                 if (count == successcount)
                 {
                     alert("保存成功。");
                 }
                 else
                 {
                     alert("保存失败。");
                 }
                 return false;
             }

    </script>
</head>
<body class="easyui-layout">
    <div region="west" split="true" title="人员选择" style="width: 180px;">
        <ul id="myTree">
        </ul>
    </div>
    <div id="content" region="center" fit="true" title="操作">
        <table id="flexigridData">
        </table>
    </div>

    <input id="hidtreeid" type="hidden" />
  
</body>
</html>

